
package botlab.gui.levelchooser;

import botlab.gui.GUI;
import botlab.gui.levelchooser.actionlistener.CancelActionListener;
import botlab.gui.levelchooser.actionlistener.NextActionListener;
import botlab.gui.levelchooser.actionlistener.PreviousActionListener;
import botlab.gui.levelchooser.actionlistener.SelectActionListener;
import botlab.level.*;
import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 *
 * @author Quentin
 */
public class LevelChooserPanel extends JPanel
{
    private JSlideShowLabel slide;
    private HashMap<String,Level> levels;
    private JButton next;
    private JButton previous;
    private JButton select;
    private JButton cancel;
    private GUI gui;
    
    public LevelChooserPanel(GUI gui)
    {
        this.gui=gui;
        slide = new JSlideShowLabel();
        levels = new HashMap<String,Level>();
        
        next = new JButton("Next");
        next.addActionListener(new NextActionListener(slide));
        previous = new JButton("Previous");
        previous.addActionListener(new PreviousActionListener(slide));
        select = new JButton("Select");
        select.addActionListener(new SelectActionListener(this, gui));
        cancel = new JButton("Cancel");
        cancel.addActionListener(new CancelActionListener(slide, gui));
        
        JPanel buttons = new JPanel();
        buttons.add(previous,new PreviousActionListener(slide));
        buttons.add(next, new NextActionListener(slide));
        buttons.add(select);
        buttons.add(cancel);
        setLayout(new BorderLayout());
        add(buttons,BorderLayout.PAGE_END);
        add(slide,BorderLayout.CENTER);
        
        initLevels();
        initSlideShow();
    }
    
    private void initLevels()
    {
        levels.put("/images/levelGoThrough.png",new LevelGoThrough("0"));
        levels.put("/images/levelSpeedUp1.png",new LevelSpeedUp1("1"));
        levels.put("/images/levelGoAround.png",new LevelGoAround("2"));
    }
    
    private void initSlideShow()
    {
        for(Iterator<String> it = levels.keySet().iterator();it.hasNext();)
        {
            slide.addImage(it.next());
        }
        slide.reset();
    }

    public JSlideShowLabel getSlide()
    {
        return slide;
    }

    public HashMap<String, Level> getLevels()
    {
        return levels;
    }
    
}
